package com.scalosoft.action.form1;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.validation.SkipValidation;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")

@Namespace(value="/form1")
@Result( location = "/form1/Form.jsp")
	
public class Form extends ActionSupport {

	private String nome;
	private String cognome;
	private String eta;
	
	
	@Action(value = "Check",  results = {
			@Result(name = "success", location = "/form1/FormSuccess.jsp"),
			@Result(name = "error", location = "/form1/Error.jsp"),
			@Result(name = "input", location = "/form1/Form.jsp")
	})

	public String execute() {
		return SUCCESS;
	}
	
	@SkipValidation
	@Action(value="Form")
	public String init() {
		return SUCCESS;
	}
	
	
	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getCognome() {
		return cognome;
	}

	public void setCognome(String cognome) {
		this.cognome = cognome;
	}

	public String getEta() {
		return eta;
	}

	public void setEta(String eta) {
		this.eta = eta;
	}
	
	public void validate() {
		if (getNome().length()==0)
			addFieldError("nome", "campo richiesto");
		if (getCognome().length()==0)
			addFieldError("cognome", "campo richiesto");
		if (getEta().length()==0)
			addFieldError("eta", "campo richiesto");
	}
	
}
